package datastructure.line.queue;

import datastructure.line.Array.Array;

public class ArrayQueue<E extends Comparable<E>> implements Queue<E> {
    private Array<E> array;

    /**
     * 默认构造函数
     * 队列的初始长度默认为10
     */
    public ArrayQueue() {
        array = new Array<E>(10);
    }

    /**
     * 带参构造
     *
     * @param size 队列的初始长度
     */
    public ArrayQueue(int size) {
        this.array = new Array<E>(size);
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Queue: front [");
        for (int i = 0; i < array.getSize(); i++) {
            sb.append(array.get(i));
            if (i != array.getSize() - 1) {
                sb.append(", ");
            }
        }
        sb.append("] tail");
        return sb.toString();
    }
}
